<template>
    <div class="wrapper" ref="wrapper">
        <div class="content">
            <slot></slot>
        </div>
    </div>
</template>
<script>
import BScroll from 'better-scroll';
export default {
    name:'Scroll',
    data(){
        return {
            scroll:null
        }
    },
    mounted(){
        this.scroll = new BScroll(this.$refs.wrapper,{
            probeType:2,
            pullUpLoad:true,
            click:true
        });
        this.scroll.on('scroll',(position)=>{
           // console.log(position);
            this.$emit('scrolls',position)
        })
        this.scroll.on('pullingUp',()=>{
        //    console.log('上拉触发上啦');
            this.$emit('pullingUp');
        });

    },
    methods: {
        // 定位
        scrollTo(x=0,y=10,time=300){
            console.log('触发了滑块的点击上滑事件');
             this.scroll && this.scroll.scrollTo(x,y,time);
            //  console.log(this.scroll.scrollTo);
            // console.log(this.scroll.scrollTo());
        },
        // 重新渲染
        refresh(){
            console.log('利用防抖函数减少了 触发了重新渲染 的次数');
           this.scroll && this.scroll.refresh && this.scroll.refresh()
        },
        //
        finishPullUp() {
            this.scroll && this.scroll.finishPullUp();
      }
    },
}
</script>
<style scoped>

</style>